import {
  SHOW_SUCCESS_MSG,
  SHOW_ERROR_MSG
} from '../mutation-types'

const state = {
  type: '', //消息主题 success/warning/info/error
  message: '', //消息文字
  duration: 0, //显示时间, 毫秒。设为 0 则不会自动关闭
  count: 0, //消息计数触发消息提示
  needRedirect: false, //是否需要路由跳转
  redirectPathName: '', //路由跳转路径的name 如 Main
  needGoBack: false, //是否需要路由回退
}

const getters = {}

const actions = {}

const mutations = {
  [SHOW_SUCCESS_MSG](state, msg) {
    state.type = "success";
    state.message = msg.message;
    state.duration = msg.duration || 3000;
    state.needRedirect = msg.needRedirect || false;
    state.redirectPathName = msg.redirectPathName || '';
    state.needGoBack = msg.needGoBack || false;
    state.count = state.count + 1;
  },
  [SHOW_ERROR_MSG](state, msg) {
    state.type = "error";
    state.message = msg.message;
    state.duration = msg.duration || 0;
    state.needRedirect = msg.needRedirect || false;
    state.redirectPathName = msg.redirectPathName || '';
    state.needGoBack = msg.needGoBack || false;
    state.count = state.count + 1;
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
